﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

public partial class Watching : System.Web.UI.Page
{
    private bool isFavorite;
    private bool isWatchlist;
    private int movieId = 0;
    private UserSub userSub = new UserSub();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.User.Identity.IsAuthenticated)
        {
            if (!Page.IsPostBack)
            {
                mvAuthentication.SetActiveView(view1);
                try
                {
                    movieId = Int32.Parse(Request.QueryString["id"]);
                }
                catch (Exception ex)
                {
                    Response.Redirect("Ooops.aspx");
                }
                Movie movie = MovieAccess.GetMovieDetails(movieId);
                userSub = SubsciptionAccess.GetUserSubscription(User.Identity.Name);
                if (userSub.idSubscription == 0 && movie.promoBit == false && movie.freeBit == false)
                {
                    mv.SetActiveView(viewUnsigned);
                }
                //tuka treba da se stavi za watchlist i favourite
                else
                {
                    mv.SetActiveView(viewUser);
                    lblCast.Text = movie.cast;
                    lblDescription.Text = movie.description;
                    lblTitle.Text = movie.title;
                    startVideo(movie);
                    //chkWatchlist.Checked = false;
                }
            }
        }
        else
        {
            mvAuthentication.SetActiveView(view2);
        }
    }

    private void startVideo(Movie movie)
    {
        string moviePath= "data/videos/"+movie.srcPath;
        String script = "<script type='text/javascript'>jwplayer('myElement').setup({file: '" + moviePath + "',image: '43.jpg', \"width\": 800,\"height\": 450,});</script>";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "video", script, false);
    }
   

    protected void chkWatchlist_CheckedChanged(object sender, EventArgs e)
    {
        if (chkWatchlist.Checked)
        {
            MovieAccess.AddWatchlistMovie(movieId, User.Identity.Name);
        }
        else
        {
            MovieAccess.RemoveWatchlistMovie(movieId, User.Identity.Name);
        }
    }
    protected void chkFavorites_CheckedChanged(object sender, EventArgs e)
    {
        MovieAccess.AddFavouriteMovie(movieId, User.Identity.Name);
    }
}